package com.itheima.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.SetmealMapper;
import com.itheima.pojo.Setmeal;
import com.itheima.service.CheckGroupService;
import com.itheima.service.CheckItemService;
import com.itheima.service.SetmealGroupService;
import com.itheima.service.SetmealService;
import com.itheima.vo.CheckGroupVO;
import com.itheima.vo.SetmealVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class SetmealServiceImpl extends ServiceImpl<SetmealMapper, Setmeal> implements SetmealService {

    @Autowired
    CheckGroupService checkGroupService;

    @Autowired
    SetmealGroupService setmealGroupService;

    @Autowired
    CheckItemService checkItemService;


    @Override
    public List<Setmeal> findAll() {
        List<Setmeal> list = this.list();
        return list;
    }

    @Override
    public SetmealVO findSetMailDetail(Long id) {
        //根据套餐id查询出套餐详情
        SetmealVO setmealvo = this.baseMapper.findByStemId(id);
        System.out.println("------>");
        System.out.println("setmealvo = " + setmealvo.getAge());
        //根据套餐id查询所有组

        List<CheckGroupVO> checkGroupVOS = checkGroupService.findBySetmealId(id);
//        List<SetmealGroup> setmealGroups = setmealGroupService.findByGroupId(id);
        //检查项信息

        setmealvo.setCheckGroups(checkGroupVOS);
        System.out.println("------>");
        System.out.println(checkGroupVOS);
        System.out.println("checkGroupVOS = " + checkGroupVOS.get(0).getId());
        for (CheckGroupVO checkGroupVO:checkGroupVOS){
            checkGroupVO.setCheckItems(checkItemService.findByGroupId(checkGroupVO.getId()));
        }
        System.out.println("------->");
        System.out.println("setmealvo"+setmealvo);
        return setmealvo;
    }
}
